<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/share/jquery.confirm/jquery.confirm/jquery.confirm.css"/>
    <!--<script src="__PUBLIC__/share/codemirror-4.0/lib/codemirror.js"></script>-->
    <!--<link rel="stylesheet" href="__PUBLIC__/share/codemirror-4.0/lib/codemirror.css">-->
    <!--<link rel="stylesheet" href="__PUBLIC__/share/codemirror-4.0/theme/solarized.css">-->
    <!--<script src="__PUBLIC__/share/codemirror-4.0/mode/javascript/javascript.js"></script>-->
    <!--<script src="__PUBLIC__/share/codemirror-4.0/addon/edit/matchbrackets.js"></script>-->

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{:get_opinion('title')}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-10">

                    <!-- /.box-header -->
                    <div class="box-body">


                        <!-- BEGIN FORM-->
                        <form id="form" action="{:U('Admin/Custom/build')}" method="post" class="form-horizontal">
                            <div class="form-group">
                                <label class="control-label">*标识名</label>

                                <div class="controls">
                                    <input type="text" placeholder="Example" class="form-control large"
                                           name="info[name]" value=""/>
                                    <span class="help-inline">插件标识（英）</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">插件名</label>

                                <div class="controls">
                                    <input type="text" placeholder="示例" class="form-control large" name="info[title]"/>
                                    <span class="help-inline">插件名称（中）</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">版本</label>

                                <div class="controls">
                                    <input type="text" placeholder="0.1" class="form-control large" name="info[version]"
                                           value="0.1"/>
                                    <span class="help-inline">插件版本号</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">作者</label>

                                <div class="controls">
                                    <input type="text" placeholder="V.K Chow GameCC Studio" class="form-control large"
                                           name="info[author]"/>
                                    <span class="help-inline">插件作者名称</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">描述</label>

                                <div class="controls">
                                    <input type="text" placeholder="示例插件信息" class="form-control large"
                                           name="info[description]"/>
                                    <span class="help-inline">插件的介绍信息</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">安装后启用</label>

                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" name="info[status]" value="1" checked="checked"/>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">是否需要配置</label>

                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" id="has_config" name="has_config" value="1"/>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group has_config hidden">
                                <label class="control-label">配置信息</label>

                                <div class="controls">
                                        <textarea class="span10 form-control" rows="10" name="config">
                                            &lt;?php
                                            return array(
                                            'random'=>array(//配置在表单中的键名 ,这个会是config[random]
                                            'title'=>'是否开启随机:',//表单的文字
                                            'type'=>'radio',         //表单的类型：text、textarea、checkbox、radio、select等
                                            'options'=>array(        //select 和radion、checkbox的子选项
                                            '1'=>'开启',       //值=>文字
                                            '0'=>'关闭',
                                            ),
                                            'value'=>'1',            //表单的默认值
                                            ),
                                            );
                                        </textarea>
                                </div>
                            </div>
                            <div class="form-group has_config hidden">
                                <label class="control-label">自定义模板</label>

                                <div class="controls">
                                    <input type="text" placeholder="" class="form-control large" name="custom_config"/>
                                    <span class="help-inline">注意：自定义模板里的表单name必须为config[name]这种，获取保存后配置的值用$data.config.name</span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">是否需要外部访问</label>

                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" name="has_outurl" value="1"/>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">实现的钩子方法</label>

                                <div class="controls">
                                    <select class="span6 form-control" multiple="multiple" required="required"
                                            data-placeholder="" tabindex="1" name="hook[]">
                                        <volist name="Hooks" id="vo">
                                            <option value="{$vo.name}" title="{$vo.description}">{$vo.name}</option>
                                        </volist>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">是否需要后台列表</label>

                                <div class="controls">
                                    <label class="checkbox">
                                        <input type="checkbox" id="has_adminlist" name="has_adminlist" value="1"/>
                                        <span class="help-inline">如果勾选，已装插件列表会出现该插件名，如通用社交化评论</span>
                                    </label>
                                </div>
                            </div>
                            <div class="form-group has_adminlist hidden">
                                <label class="control-label"></label>

                                <div class="controls">
                                        <textarea class="span6 form-control" rows="10" name="admin_list">
                                            'model'=>'Example',     //要查的表
                                            'fields'=>'*',          //要查的字段
                                            'map'=>'',              //查询条件, 如果需要可以再插件类的构造方法里动态重置这个属性
                                            'order'=>'id desc',     //排序,
                                            'listKey'=>array(       //这里定义的是除了id序号外的表格里字段显示的表头名
                                            '字段名'=>'表头显示名'
                                            ),
                                        </textarea>
                                </div>
                            </div>
                            <div class="form-group has_adminlist hidden">
                                <label class="control-label">自定义模板</label>

                                <div class="controls">
                                    <input type="text" placeholder="" class="text form-control large" id="has_adminlist"
                                           name="custom_adminlist"/>
                                    <span class="help-inline">注意：自定义模板里的列表变量为$_list这种,遍历后可以用listkey可以控制表头显示,也可以完全手写，分页变量用$_page</span>
                                </div>
                            </div>
                            <div id="preview_window" style="display:none;"><textarea id="code"></textarea></div>
                            <div class="form-actions success_info">
                                <button type="button" class="btn black" id="reset" style="display:none;">重置</button>
                                <button type="button" class="btn btn-info" id="preview">预览</button>
                                <button type="button" class="btn btn-danger ajax_create" target-form="form-horizontal"
                                        id="submit">创建
                                </button>
                                <button type="button" class="btn btn-primary"
                                        onclick="javascript:history.back(-1);return false;">取消
                                </button>
                            </div>
                        </form>


                    </div>
                </div>
            </div>


        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>
<script type="text/javascript">
    function bindShow(radio_bind, selectors) {
        $(radio_bind).click(function () {
            $(selectors).toggleClass('hidden');
        })
    }

    $(window).bind('scrollstart');
    $(window).bind('scrollstop');


    //配置的动态
    bindShow('#has_config', '.has_config');
    bindShow('#has_adminlist', '.has_adminlist');

    //    var codemirror_option = {
    //        lineNumbers   :true,
    //        styleActiveLine: true,
    //        matchBrackets :true,
    //        mode          :"application/x-httpd-php",
    //        indentUnit    :4,
    //        gutter        :true,
    //        fixedGutter   :true,
    //        indentWithTabs:true,
    //        readOnly      :true,
    //        lineWrapping  :true,
    //        height        :500,
    //        enterMode     :"keep",
    //        tabMode       :"shift",
    //        theme: "solarized dark"
    //    };
    //    var preview_window = $("#preview_window").find("textarea");
    //    var editor = CodeMirror.fromTextArea(preview_window[0], codemirror_option);
    //
    //    $('#preview').click(function(){
    //        var preview_url = '{:U("Admin/Custom/preview")}';
    //        console.log($('#form').serialize());
    //        $.post(preview_url, $('#form').serialize(),function(data){
    //            $("#preview_window").fadeIn();
    //            editor.setValue(data);
    //            $("#reset").fadeIn();
    //            $("#preview").fadeOut();
    //            $("html,body").animate({scrollTop:$("#preview_window").offset().top},1000);
    //        });
    //        return false;
    //    });
    $('#reset').click(function () {
        $("#preview_window").fadeOut();
        $("#reset").fadeOut();
        $("#preview").fadeIn();
        editor.setValue();
    });

    $('.ajax_create').click(function () {
        var target, query, form;
        var target_form = $(this).attr('target-form');
        var check_url = '{:U("Admin/Custom/checkForm")}';
        $.ajax({
            type: "POST",
            url: check_url,
            dataType: 'json',
            async: false,
            data: $('#form').serialize(),
            success: function (data) {
                if (data.status) {
                    if (($(this).attr('type') == 'submit') || (target = $(this).attr('href')) || (target = $(this).attr('url'))) {
                        form = $('.' + target_form);
                        if (form.get(0).nodeName == 'FORM') {
                            target = form.get(0).action;
                            query = form.serialize();
                        } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                            query = form.serialize();
                        } else {
                            query = form.find('input,select,textarea').serialize();
                        }

                        $.post(target, query).success(function (data) {
                            if (data.status == 1) {
                                if (data.url) {
                                    $(".success_info").html(data.info + '等待页面自动跳转');
                                } else {
                                    $(".success_info").html(data.info + '等待页面自动跳转');
                                }
                                setTimeout(function () {
                                    if (data.url) {
                                        location.href = data.url;
                                    } else {
                                        location.reload();
                                    }
                                }, 1500);
                            } else {
                                $(".success_info").html(data.info);
                                location.reload();
                            }
                        });
                    }
                } else {
                    $(".success_info").html(data.info);
                    location.reload();
                }
            }
        });

        return false;
    });
</script>
</body>
</html>